'''
作业3：
使用jieba对“三国演义”中的词频进行统计并输出。
'''

import jieba

def get_text():
    f = open('三国演义.txt','r',encoding='utf-8').read()#读取文件
    words = jieba.lcut(f)#获取分词
    return words

words = get_text()

counts = {}
for i in words:
    if len(i)==1:
        continue
    else:
        counts[i] = counts.get(i,0)+1

# print(counts)


ls = list(counts.items())
ls.sort(key= lambda x:x[1],reverse=True)
# print(ls)

for i in ls[:20]:
    print(i)